package com.as3.timbot.command
{
	import com.as3.timbot.command.AbstractCommand;
	import flash.utils.Timer;
    import flash.events.TimerEvent;

	public class PauseCommand extends AbstractCommand
	{
		private var __pause:Number;
		private var __count:Number;
		private var __timerProgress:Timer;
		
		public function PauseCommand(value:Number)
		{
			trace("timer created");
			__pause = value;
		};
		override public function execute():void
		{
			__timerProgress = new Timer(10);
			var myTimer:Timer = new Timer(__pause, 1);
            myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerCompleteHandler);
            __timerProgress.addEventListener("timer",progressHandler);
            super.begin();
            myTimer.start();
            if(__pause>10){
            	__timerProgress.start();
            }
		}
		private function progressHandler(ev:TimerEvent):void
		{
			__count ++;
			var prog:Number = ((__count*10)/__pause)*100;
			super.progress(prog);
		}
		private function timerCompleteHandler(ev:TimerEvent):void
		{
			__timerProgress.stop();
			super.end();
		}
	}
}